package com.study.newjava8.test;

import com.study.newjava8.pojo.Employee;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

public class SteamAPITest1 {
    @Test
    public void test1(){
        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5);
        List<Integer> collect = list.stream()
                .map(e -> e * e)
                .collect(Collectors.toList());
        System.out.println(collect);
    }
    List<Employee> employees = Arrays.asList(
            new Employee("huangsm", 22, 40020.0, Employee.Status.BUSY),
            new Employee("huangsm1", 24, 52300.0, Employee.Status.FREE),
            new Employee("huangsm1", 24, 52300.0, Employee.Status.VOCATION),
            new Employee("huangsm1", 24, 52300.0, Employee.Status.VOCATION),
            new Employee("huangsm2", 26, 40100.0, Employee.Status.FREE)
    );

    /**
     * 怎么用map和reduce完成查询employees有多少个员工
     */
    @Test
    public void test2(){

        Optional<Integer> reduce = employees.stream()
                .map((e) -> 1)
                .reduce(Integer::sum);
        System.out.println(reduce.get());
    }


}
